package com.demo.config;

import com.demo.commons.BaseConsts;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerAConfig {

    public Docket createDocekt() {
        //全局参数列表定义
        List<Parameter> ps = Arrays.asList(new ParameterBuilder().required(false).modelRef(new ModelRef("string"))
        .parameterType("header").name(BaseConsts.TOKEN_KEY).description("Token").build());

        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("产品信息接口").description("接口说明")
                .version("1.0")
                .contact(new Contact("杨森",
                        "xxxx",
                        "xxxx"))
                .build();
        return docket.apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.demo.controller"))
                .paths(PathSelectors.any())
                .build()
                //添加全局参数列表
                .globalOperationParameters(ps);
    }
}
